package redisKey

import (
	"fmt"
	"strings"

	"public.com/goutil/typeUtil"
)

type RankKey string

// key
const (
	// 据点信息
	TerritoryPrefix = "Uncharted_Territory_"

	// 每5分钟的排名
	Uncharted_HourRankKey RankKey = "Uncharted_HourRankKey"

	// 上赛季排名
	Uncharted_SeasonRankKey RankKey = "Uncharted_SeasonRankKey"
)

// 玩家数据
const (
	// 玩家当前所在地图
	Uncharted_MapId = "Uncharted_MapId"

	// 玩家当前星数
	Uncharted_Star = "Uncharted_Star"

	// 玩家当前积分
	Uncharted_Score = "Uncharted_Score"

	// 最近一次积分变更时间
	Uncharted_ScoreChangeTime = "Uncharted_ScoreChangeTime"

	// 玩家据点占领的临时积分
	Uncharted_TempTerritoryScore = "Uncharted_TempTerritoryScore"
)

// 领地数据
const (
	// 玩家数据
	Uncharted_FightData = "FightData"

	// 占领时间
	Uncharted_TerritoryTime = "TerritoryTime"

	// 玩家Id
	Uncharted_PlayerId = "PlayerId"

	// 学员数据
	Uncharted_HeroInfo = "HeroInfo"
)

func GetTerritoryKey(mapId int8, pointId int) string {
	return fmt.Sprintf("%s%d_%d", TerritoryPrefix, mapId, pointId)
}

// 把key字符串转换为mapId和pointid
// key:待处理的字符串
// 返回值:
// mapId:地图Id
// pointId:节点Id
// ok:处理结果
func ParseTerritoryKey(key string) (mapId int8, pointId int, ok bool) {
	key = strings.TrimPrefix(key, TerritoryPrefix)
	vals := strings.Split(key, "_")
	if len(vals) != 2 {
		return 0, 0, false
	}
	val, err := typeUtil.Int(vals[0])
	if err != nil {
		return 0, 0, false
	}

	mapId = int8(val)

	pointId, err = typeUtil.Int(vals[1])
	if err != nil {
		return 0, 0, false
	}

	return mapId, pointId, true
}
